//DevNETCoder
//CopyRight By DevNET Group
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using STT.Entities;
using STT.DataAccess;
 
namespace STT.Business
{
    public class BTbHocVien_NoiTru
    {
        public static DataTable Search(ETbHocVien_NoiTru lk)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaHV", lk.MaHV);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHocVienNoiTru_Search", pr);
            return all;
        }
        public static bool KiemTraDuLieu(ETbHocVien_NoiTru lk)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaHV", lk.MaHV);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHocVienNoiTru_KiemTraDuLieu", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
//-----------------------------------------------------------//
        public static DataTable SelectAll()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHocVien_NoiTru_SelectAll", null);
            return all;
        }
//-----------------------------------------------------------//
        public static void Insert(ETbHocVien_NoiTru OTbHocVien_NoiTru)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"MaHV", OTbHocVien_NoiTru.MaHV);
            pr[1] = new SqlParameter(@"DiaDiem", OTbHocVien_NoiTru.DiaDiem);
            pr[2] = new SqlParameter(@"Phong", OTbHocVien_NoiTru.Phong);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbHocVien_NoiTru_Insert", pr);
        }
//-----------------------------------------------------------//
        public static void Update(ETbHocVien_NoiTru OTbHocVien_NoiTru)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"MaHV", OTbHocVien_NoiTru.MaHV);
            pr[1] = new SqlParameter(@"DiaDiem", OTbHocVien_NoiTru.DiaDiem);
            pr[2] = new SqlParameter(@"Phong", OTbHocVien_NoiTru.Phong);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbHocVien_NoiTru_Update", pr);
        }
//-----------------------------------------------------------//
        public static void Delete(string MaHV)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaHV",MaHV);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbHocVien_NoiTru_Delete", pr);
        }
//-----------------------------------------------------------//
        public static ETbHocVien_NoiTru SelectByID(string MaHV)
        {
            ETbHocVien_NoiTru OTbHocVien_NoiTru = new ETbHocVien_NoiTru();
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaHV",MaHV);
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure,"TbHocVien_NoiTru_SelectByID", pr);
            if (idr.Read())
              OTbHocVien_NoiTru = GetOneTbHocVien_NoiTru(idr);
            idr.Close();
            idr.Dispose();
            return OTbHocVien_NoiTru;
        }
//-----------------------------------------------------------//
        private static ETbHocVien_NoiTru GetOneTbHocVien_NoiTru(IDataReader idr)
       {
            ETbHocVien_NoiTru OTbHocVien_NoiTru = new ETbHocVien_NoiTru();
                if (idr["MaHV"] != DBNull.Value)
                    OTbHocVien_NoiTru.MaHV = (string)idr["MaHV"];
                if (idr["DiaDiem"] != DBNull.Value)
                    OTbHocVien_NoiTru.DiaDiem = (string)idr["DiaDiem"];
                if (idr["Phong"] != DBNull.Value)
                    OTbHocVien_NoiTru.Phong = (string)idr["Phong"];
            return OTbHocVien_NoiTru;
       }
//-----------------------------------------------------------//
        public static bool TestByID(string MaHV)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaHV",MaHV);
            pr[1] = new SqlParameter(@"TestID",SqlDbType.Bit);
            pr[1].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbHocVien_NoiTru_TestByID", pr);
            return Convert.ToBoolean(pr[1].Value);
        }
//-----------------------------------------------------------//
        public static List<ETbHocVien_NoiTru> ListAll()
        {
            List<ETbHocVien_NoiTru> list = new List<ETbHocVien_NoiTru>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbHocVien_NoiTru_SelectAll", null);
            while (idr.Read())
              list.Add(GetOneTbHocVien_NoiTru(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }
    }
 
}
